Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more informative check_arg #1031

Merged
merged 9 commits into from
Oct 24, 2024
Merged

Use more informative check_arg #1031

merged 9 commits into from
Oct 24, 2024

Conversation

strengejacke
Copy link
Member

No description provided.

R/utils.R Outdated Show resolved Hide resolved
Co-authored-by: Brenton M. Wiernik <[email protected]>
@strengejacke
Copy link
Member Author

Maybe, when we have this wording, it would make sense to remove the suggested options from those that follow after "Otherwise...". Else, they would be duplicated.

@bwiernik
Copy link
Contributor

Good call

@strengejacke
Copy link
Member Author

strengejacke commented Oct 19, 2024

I added that function to insight, so we can use it in other packages, too:

library(insight)
foo1 <- function(test = "short_distance") {
  validate_argument(test, c("short_distance", "long_distance", "medium_distance"))
}

# match
foo1("medium_distance")
#> [1] "medium_distance"

# typo
foo1("medium_ditsance")
#> Error: Invalid option for argument `test`. Did you mean "medium_distance"?
#>   Otherwise, use one of the following options: "short_distance" or
#>   "long_distance"

# no match
foo1("abcabcabc")
#> Error: Invalid option for argument `test`. Please use one of the following
#>   options: "short_distance", "long_distance" or "medium_distance"

Created on 2024-10-19 with reprex v2.1.1

@strengejacke strengejacke merged commit a37c5e4 into main Oct 24, 2024
19 of 20 checks passed
@strengejacke strengejacke deleted the use_check_arg branch October 24, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants